package opdracht3.mark.pim;

import java.util.ArrayList;

public class TrieNode {

	//fields
	
	private char character;
	private Data data;
	private TrieNode[] children;
	private boolean completed = false;
	
	//constructors
	
	public TrieNode(Data data) {
		this.data = data;
		children = new TrieNode[26];
	}
	
	public TrieNode() {
		children = new TrieNode[26];
	}
	
	public void insert(String s, Data d ) {
		s = s.toUpperCase();
		System.out.println(s);
		int val = s.charAt(0) - 64;
		//System.out.print(val);
		
		if(Character.isLetter(s.charAt(0))) {
			if(children[val] == null) {
				children[val] = new TrieNode();
				children[val].character = s.charAt(0);
			}
			
			//als het woord langer is dan 1, dan is het woord nog niet klaar met invoeren
			//anders is het woord klaar en dan kan de completed flag gezet worden
			if(s.length() > 1) {
				children[val].insert(s.substring(1), d);
			} else {
				//hier de completed flag zetten
				children[val].completed = true;
			}
		}
		
		
	}
	
	public void delete(String s) {
		s = s.toUpperCase();
		int val = s.charAt(0) - 64;
		
		if(children[val] == null) {
			//het woord bestaat niet
			System.out.println("het woord staat niet in de trie");
		} else {
			
		}
	}
	
	
	//getters
	public char getChildren() {
		System.out.print(character);
		for(int i = 0; i <= 25; i++) {
			if(children[i] != null) {
				children[i].getChildren();
			}
		}
		return character;
		
		
	}

	public char getCharacter() {
		return character;
	}

	public Data getData() {
		return data;
	}
	
	
	
	
}
